From 3be9591d1c4018ae210f0196759b94b363a1e9c6 Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Mon, 5 Sep 2005 08:23:05 +0000 Subject: [PATCH] Free grant reference when block device shuts down. Signed-off-by: Christian Limpach --- linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c index d3caf467c8..136f7d68d9 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -58,6 +58,7 @@ static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED; #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) #define GRANTREF_INVALID (1<<15) +#define GRANT_INVALID_REF (0xFFFF) static int recovery = 0; /* Recovery in progress: protected by blkif_io_lock */ @@ -368,6 +369,9 @@ static void blkif_free(struct blkfront_info *info) free_page((unsigned long)info->ring.sring); info->ring.sring = NULL; } + if (info->ring_ref != GRANT_INVALID_REF) + gnttab_end_foreign_access(info->ring_ref, 0); + info->ring_ref = GRANT_INVALID_REF; unbind_evtchn_from_irqhandler(info->evtchn, info); info->evtchn = 0; } @@ -502,6 +506,8 @@ static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info) evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound }; int err; + info->ring_ref = GRANT_INVALID_REF; + sring = (void *)__get_free_page(GFP_KERNEL); if (!sring) { xenbus_dev_error(dev, -ENOMEM, "allocating shared ring"); @@ -524,6 +530,7 @@ static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info) err = HYPERVISOR_event_channel_op(&op); if (err) { gnttab_end_foreign_access(info->ring_ref, 0); + info->ring_ref = GRANT_INVALID_REF; free_page((unsigned long)info->ring.sring); info->ring.sring = 0; xenbus_dev_error(dev, err, "allocating event channel"); -- 2.30.2